package tech.yunland.shop.domain.model;

import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 单号
 *
 * @author 袁首京<yuanshoujing@gmail.com>
 */
@Entity
@Table(name = "serial_no")
public class SN extends AbstractVersionEntity {

    @Column(name = "t_key", length = 100, nullable = false)
    private String key; // 读取关键字

    @Column(name = "organ_id", length = 36, nullable = false)
    private String organId; // 所属机构

    @Column(length = 30, nullable = false)
    private String prefix; // 前缀

    @Column(nullable = false)
    private Integer year; // 年份

    @Column(nullable = false)
    private Integer month; // 月份

    @Column(nullable = false)
    private int numSize; // 流水位数

    @Column(nullable = false)
    private int num = 1; // 当前流水

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getOrganId() {
        return organId;
    }

    public void setOrganId(String organId) {
        this.organId = organId;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public int getNumSize() {
        return numSize;
    }

    public void setNumSize(int numSize) {
        this.numSize = numSize;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    @Override
    public String toString() {
        String s = StringUtils.leftPad(String.valueOf(num), numSize, '0');
        String m = StringUtils.leftPad(String.valueOf(month), 2, '0');
        return StringUtils.trimToEmpty(prefix) + year + m + s;
    }
}
